package ATMAgain;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class TakeMoneyFrame extends JFrame {

    ICodeService service = new CodeServiceImpl();
    MyJText get = new MyJText("请输入取款金额",50,100,this);

    public TakeMoneyFrame(){
        this.setLayout(null);

        this.init();

        this.setSize(500,300);
        this.setVisible(true);
        this.setDefaultCloseOperation(3);
        this.setLocationRelativeTo(null);
    }

    private void init(){
        MyButton getButton = new MyButton("取款",350,200,this);

        getButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                takeMoney();
            }
        });
    }

    private void takeMoney(){
        boolean isEnough = service.getMoney(Integer.parseInt(get.getText()));
        if (isEnough){
            TakeMoneyFrame.this.dispose();
            new FindFrame();
        }else {
            JOptionPane.showMessageDialog(null,"余额不足，无法取款");
        }
    }
}
